//
//  FounctionSectionHeaderView.swift
//  Wmsmobile
//
//  Created by Nick xu on 16/8/18.
//  Copyright © 2016年 www.hd123.com. All rights reserved.
//

import UIKit

class FounctionSectionHeaderView: UIView {
    //MARK: - property
    var headerString: String?
    
    
    init(){
        super.init(frame: CGRect(x: 0, y: 0, width: KscreenWidth, height: 40))
        self.backgroundColor = UIColor.hexStringToUIColor("#e8e8e8")
    }
    convenience init(headerString: String){
        self.init()
        self.headerString = headerString
        self.addSubview(label1)
        self.addSubview(label2)
        self.addSubview(label3)
        self.addSubview(topLine)
        let headerKeys = headerString.components(separatedBy: ",")
        
        label1.snp.makeConstraints { (make) in
            make.left.equalTo(self).offset(10)
            make.centerY.equalTo(self)
        }
        label2.snp.makeConstraints { (make) in
            make.centerY.equalTo(self)
            if headerKeys.count == 3{
                make.centerX.equalTo(self)
            }else{
                make.trailing.equalTo(self).offset(-25)
            }
        }
        label3.snp.makeConstraints { (make) in
            make.centerY.equalTo(self)
            make.trailing.equalTo(self).offset(-25)
        }
        if headerKeys.count == 2{
            label3.isHidden = true
        }
        
        label1.text = headerKeys[0]
        label2.text = headerKeys[1]
        label3.text = headerKeys.count > 2 ? headerKeys[2] : ""


    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    func getFont() -> CGFloat {
        return (WMSFonts["founctionHeader"]!)[userInfo!.fontLevel.rawValue]
    }
    
    lazy fileprivate var label1:UILabel = {
        let label = UILabel()
//        label.font = UIFont.boldSystemFontOfSize(16)
        label.font = UIFont.boldSystemFont(ofSize: self.getFont())
        label.textColor = UIColor.hexStringToUIColor("#333333")
        return label
    }()
    lazy fileprivate var label2:UILabel = {
        let label = UILabel()
//        label.font = UIFont.boldSystemFontOfSize(16)
        label.font = UIFont.boldSystemFont(ofSize: self.getFont())
        label.textColor = UIColor.hexStringToUIColor("#333333")
        return label
    }()
    lazy fileprivate var label3:UILabel = {
        let label = UILabel()
//        label.font = UIFont.boldSystemFontOfSize(16)
        label.font = UIFont.boldSystemFont(ofSize: self.getFont())
//        label.backgroundColor = UIColor.redColor()
        label.textColor = UIColor.hexStringToUIColor("#333333")
        return label
    }()
    lazy fileprivate var topLine:UIView = {
        let view = UIView(frame: CGRect(x: 0, y: 0, width: KscreenWidth, height: 0.5))
        view.backgroundColor = UIColor.hexStringToUIColor("#cccccc")
        return view
    }()

}
